<?php
if ($_SESSION['login_user']['status'] != 'admin' || LZ_MODULE != 'admin') die('Access Denied');
if($_SESSION['login_user']['status'] != 'admin')
{
	lz_exit(ACCESS_DENIED,'admin.php',1);
}
include_once('model/photo.php');
include_once('model/photo_category.php');
include_once('model/search.php');
$search = new LZ_Search;
$photo = new LZ_Photo;
$category = new LZ_Photo_Category;
$m = $_GET['m'];

if ($m == 'update' || $m == 'reedit')
{
	$data = filter_array($_POST, "photo!");
	if ($data)
	{
		$data = $data['photo'];
		$length = count($data);
		for($i=0;$i<$length;$i++)
		{
			$data[$i]['status'] = 1; 
			$id = $data[$i]['photo_id'];
			$tag = $data[$i]['tag'];
			$tag = str_replace( array(' ','，'),',',trim($tag));
			$tag = preg_replace('/\s+/','',$tag);
			$tag = preg_replace('/,{2,}/',',',$tag);
			$data[$i]['tag'] = $tag;
			unset($data[$i]['photo_id']);
			
			$photo->update($id, $data[$i]);
			
		}
		$from_url = $_SESSION['last_list_page'];

		if ($m == 'update')
		{
			!$from_url && $from_url = 'admin.php?p=photo_unpublished';
			lz_exit(UPDATE_SUCCESS, $from_url, 1);
		}
		else
		{
			!$from_url && $from_url = 'admin.php?p=photo_published';
			lz_exit(UPDATE_SUCCESS, $from_url, 1);
		}
	}
}
else
{
	$ids = $_GET['ids'];
	$id_array = explode(',',$ids);
	$i=0;
	foreach ($id_array as $val)
	{
		$val = intval($val);
		if (!$val) continue;
		$tmp = $photo->get_one($val);
		$tmp['i'] = $i++;
		$view_data['image_array'][] = $tmp;
	}
	$view_data['ids'] = $ids;
	$view_data['page_description'] = EDIT_IMAGES;
	$view_data['categories'] = $category->get_list();
	foreach($view_data['categories'] as $c)
	{
		$options .= '<option value="'.$c['category_id'].'">'.$c['name'].'</option>';
	}
	$view_data['select_options'] = $options;
	$view_data['last_list_page'] = $_SESSION['last_list_page'];
}
?>
